﻿///<reference path="_moduleReferences.ts" />

module ScrambledEggs.Modules {
    export class BabyFinale implements IModule {

        private _onUpdate: () => void;
        private _standingUp: bool = false;
        private _grew: bool = false;

        constructor() {
        }

        initialize(gameState: GameStateProvider, onUpdate: () => void ) {
            var me = this;
            var finale = $("#babyfinale");
            var play = $("#play");
            me._onUpdate = onUpdate;

            finale.find("button").not(".continue").click(function () {
                // it's safe to delete this now
                delete gameState.State.Temporary["statsToDistribute"];
                switch ($(this).attr("class")) {
                    case "diapercat":
                        play.find(".baby").hide();
                        play.find(".catstains").show();
                        gameState.State.Message = "The Cat <i>=°ᴥ°=</i> yelps <strong>LOUDLY</strong> at this offence!";
                        gameState.State.DecisionBabyFinale = BabyFinaleDecision.Poopcat;
                        break;
                    case "bangdoor":
                        play.find(".doorsound").show();
                        gameState.State.Message = "You bang the door <strong>LOUDLY</strong> in your fury.";
                        gameState.State.DecisionBabyFinale = BabyFinaleDecision.Doorbang;
                        break;
                    case "settledown":
                        play.find(".baby").hide();
                        play.find(".catpurr").show();
                        gameState.State.Message = "You settle down and pet The Cat <i>=°ᴥ°=</i>.";
                        gameState.State.DecisionBabyFinale = BabyFinaleDecision.Petcat;
                        break;
                    case "extra":
                        play.find(".baby").hide();
                        play.find(".door").animate({ marginLeft: "-200px" }, 3000);
                        gameState.State.Message = "The Cat <i>=°ᴥ°=</i> is impressed by your skill. <strong>Let it be known that you are one of the few who make their own path.</strong>";
                        gameState.State.DecisionBabyFinale = BabyFinaleDecision.Jailbreak;
                        break;
                    default:
                        console.warn("dafuq did you do?!");
                        break;
                }
                setTimeout(function () {
                    switch (gameState.State.DecisionBabyFinale) {
                        case BabyFinaleDecision.Poopcat:
                            gameState.State.Message = "The Cat <i>=°ᴥ°=</i>'s cries are heard far and wide. Your parents find their way into the room and <strong>laugh</strong>. Victory is yours. The Cat <i>=°ᴥ°=</i> gets a humiliating bath and you grow into a <strong>cunning</strong> young " + (gameState.State.Gender == Gender.Male ? "boy" : "girl") + ".";
                            break;
                        case BabyFinaleDecision.Petcat:
                            gameState.State.Message = "The Cat <i>=°ᴥ°=</i> purrs contently. She recognizes your big heart and decides to be <strong>your ally</strong> from now on. You grow up to be a <strong>gentle</strong> young " + (gameState.State.Gender == Gender.Male ? "boy" : "girl") + ".";
                            break;
                        case BabyFinaleDecision.Doorbang:
                            gameState.State.Message = "Your parents rush in, alarmed by the sound of your <strong>fierce banging</strong>. You learn to never give up, and grow up to be a <strong>strong</strong> young " + (gameState.State.Gender == Gender.Male ? "boy" : "girl") + ".";
                            break;
                        case BabyFinaleDecision.Jailbreak:
                            gameState.State.Message = "Through your hard work you are able to <strong>overcome all challenges</strong> by yourself. You grow up to be a <strong>smart, powerful and independant</strong> young " + (gameState.State.Gender == Gender.Male ? "boy" : "girl") + ".";
                            break;
                        default:
                            console.warn("dafuq did you do?!");
                            break;
                    }
                    me._onUpdate();
                }, 5000);
                me._onUpdate();
            });
            
            finale.find(".continue").click(function () {
                gameState.State.Phase = GamePhase.YoungAdult;
                me._onUpdate();
                $("button.save").click();
                gameState.State.Message = "Game Saved - You're a young adult now!";
                $(this).hide();
            });
        }

        update(gameState: GameStateProvider, triggerSource: IModule): void {
            // finale is shown from play
            if (gameState.State.DecisionBabyFinale != BabyFinaleDecision.None && gameState.State.Phase == GamePhase.Baby) {
                $("#babyfinale button").not(".continue").hide();
                setTimeout(function () {
                    $("#babyfinale button.continue").show();
                }, 5000);
            }
        }
    }
}